package com.juno.cafeNoa.admin.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.juno.cafeNoa.admin.R;
import com.juno.cafeNoa.admin.data.Average;

public class AverageADP extends ArrayAdapter<Average> {
	private Context mContext;
	private int mResource;
	private ArrayList<Average> mList;
	private LayoutInflater mInflater;

	public AverageADP(Context context, int layoutResource, ArrayList<Average> list) {
		super(context, layoutResource, list);
		this.mContext = context;
		this.mResource = layoutResource;
		this.mList = list;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null || convertView.getId() != mResource) {

			convertView = mInflater.inflate(mResource, null);
			holder = new ViewHolder();
			holder.date = (TextView) convertView.findViewById(R.id.averageDate);
			holder.sell = (TextView) convertView.findViewById(R.id.averageSell);
			holder.card = (TextView) convertView.findViewById(R.id.averageCard);
			holder.visit = (TextView) convertView.findViewById(R.id.averageVisit);
			holder.point = (TextView) convertView.findViewById(R.id.averagePoint);

			convertView.setTag(holder);
			convertView.setId(R.layout.row_order);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.date.setText(mList.get(position).getDate());
		holder.sell.setText(String.valueOf(mList.get(position).getAmount()));
		holder.card.setText(String.valueOf(mList.get(position).getCard()));
		holder.point.setText(String.valueOf(mList.get(position).getPoint()));
		holder.visit.setText(String.valueOf(mList.get(position).getVisit()));
		return convertView;
	}
	class ViewHolder {
		TextView date;
		TextView sell;
		TextView card;
		TextView visit;
		TextView point;
	}
	
}
